package com.eqdd.yiqidian.ui.gongneng.renshi.finance

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.bean.CheckerBean
import kotlinx.android.synthetic.main.list_item_120.view.*
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * @author吕志豪 .
 * @date 18-3-21  上午10:30.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */
class CheckerListAdapter(val mContext: Context) : RecyclerView.Adapter<CheckerListAdapter.ItemViewHoplder>() {
    var dataList: List<CheckerBean> = arrayListOf()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHoplder {
        val inflater = LayoutInflater.from(mContext);
        return ItemViewHoplder(inflater.inflate(R.layout.list_item_120, parent, false))
    }

    override fun onBindViewHolder(holder: ItemViewHoplder, position: Int) {
        val data = dataList[position]
        holder.itemView.let {
            it.tv_name.text = data.name
            it.tv_company.text = data.dename
            it.tag = data
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }


    inner class ItemViewHoplder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        init {
            itemView.onClick {
                val data = itemView.tag as CheckerBean
                val intent = Intent()
                intent.putExtra("data", data)
                (mContext as Activity).setResult(Activity.RESULT_OK, intent)
                mContext.finish()
            }
        }
    }
}